import 'package:flutter/material.dart';

//可通过widget的构造函数来传递参数
class Todo{
  final String title;
  final String description;
  Todo(this.title, this.description);
}

class TodoScreen extends StatelessWidget{
  final List<Todo> todos;
  TodoScreen({Key? key, required this.todos}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Todos'),
      ),
      body: ListView.builder(
          itemBuilder: (BuildContext context, int index){
            return ListTile(
              title: Text(todos[index].title),
              onTap: (){
                Navigator.push(context, MaterialPageRoute(builder: (BuildContext context)=>DetailScreen(todo:todos[index])));
              },
            );
          }
      ),
    );
  }
}

class DetailScreen extends StatelessWidget{
  final Todo todo;
   DetailScreen({Key? key, required this.todo}) : super(key: key);

   @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('${todo.title}'),),
      body: Padding(padding: EdgeInsets.all(16.0),
      child: Text('${todo.description}'),),
    );
  }
}

class NavigatorEx extends StatelessWidget
{
  @override
  Widget build(BuildContext context) {
    return TodoScreen(todos: List.generate(20, (index) => Todo('Todo $index', 'A Description of what needs to be done for Todo $index')));
  }
}